//
//  OutOfTimeBuyCell.m
//  CenturyCity
//
//  Created by beisheng03 on 2017/12/18.
//  Copyright © 2017年 beisheng. All rights reserved.
//

#import "OutOfTimeBuyCell.h"
#import "OutOfTimeBuyItemCell.h"
#import "GoodDetailController.h"
@interface OutOfTimeBuyCell ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *leftLabel;
@property (weak, nonatomic) IBOutlet UILabel *rightLabel;
@property (weak, nonatomic) IBOutlet UICollectionView *myCollectionView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *bottomMargin;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *myCollectionH;

@end

@implementation OutOfTimeBuyCell


- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    self.leftLabel.font = MYFONT(17);
    self.rightLabel.font = MYFONT(15);
    
    self.leftLabel.textColor = [UIColor redColor];
    
    self.rightLabel.textColor = colorWith(64, 103, 10);
    
    self.myCollectionH.constant = 260;
 
    self.myCollectionView.delegate = self;
    self.myCollectionView.dataSource = self;
    self.bottomMargin.constant = 0;
    [self.myCollectionView registerNib:[UINib nibWithNibName:NSStringFromClass([OutOfTimeBuyItemCell class]) bundle:nil]forCellWithReuseIdentifier:[OutOfTimeBuyItemCell identifierStr]];
    self.myCollectionView.showsHorizontalScrollIndicator = NO;
    self.myCollectionView.backgroundColor = viewBgGrey;
//    self.myCollectionView.pagingEnabled = YES;
    

    
}

- (void)setModel:(MarketHomeModel *)model{
    _model = model;
    
    
    [self.myCollectionView reloadData];
    
    
    
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
    
    if (self.model == 0) {
        return 0;
    } else {
        return 1;
    }
    
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    
    if (self.model == 0) {
        return 0;
    } else {
        return self.model.xianshi.count;
    }
}


- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    OutOfTimeBuyItemCell *temp = (OutOfTimeBuyItemCell *)[collectionView dequeueReusableCellWithReuseIdentifier:[OutOfTimeBuyItemCell identifierStr] forIndexPath:indexPath];
    
    //    temp.contentView.backgroundColor = randomColor;
    
    temp.model = self.model.xianshi[indexPath.item];
    
    
    
    return temp;
    
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
    GoodDetailController *tempVC = [[GoodDetailController alloc]init];
    
    MarketHSubModel *subModel = self.model.xianshi[indexPath.item];
    
    OneGoodsModel *tempModel = [[OneGoodsModel alloc]init];
    
    tempModel.goods_id = subModel.goods_id;
    
    tempModel.goods_image_url = subModel.pic_cover_small;
    
    tempVC.goodsModel = tempModel;
    
    [self.viewController.navigationController pushViewController:tempVC animated:YES];
    
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end
